package xyz.ddlnt.user.usr.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.commonutil.util.HttpUtils;
import xyz.ddlnt.model.dto.FollowDTO;
import xyz.ddlnt.model.dto.PageDTO;
import xyz.ddlnt.model.vo.FollowVO;
import xyz.ddlnt.serviceusrclient.client.FollowFeignClient;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/10 22:47
 */
@Slf4j
@Tag(name = "关注测试接口")
@RequestMapping("/follow")
@RestController
@RequiredArgsConstructor
public class FollowController {
    @Resource
    private FollowFeignClient followFeignClient;

    @Operation(summary = "关注用户")
    @PutMapping("/followUser/{id}")
    Result<Boolean> followUser(@PathVariable Long id, HttpServletRequest request) {
        FollowDTO followDTO = FollowDTO.builder()
                .followerId(HttpUtils.getId(request))
                .followedId(id)
                .build();
        return followFeignClient.FollowUser(followDTO);
    }

    @Operation(summary = "取消关注用户")
    @PutMapping("/unfollowUser/{id}")
    Result<Boolean> unfollowUser(@PathVariable Long id, HttpServletRequest request) {
        FollowDTO followDTO = FollowDTO.builder()
                .followerId(HttpUtils.getId(request))
                .followedId(id)
                .build();
        return followFeignClient.unfollowUser(followDTO);
    }

    @Operation(summary = "判断用户是否关注了某个用户")
    @GetMapping("/isFollowed/{id}")
    Result<Boolean> isFollowed(@PathVariable Long id, HttpServletRequest request) {
        FollowDTO followDTO = FollowDTO.builder()
                .followerId(HttpUtils.getId(request))
                .followedId(id)
                .build();
        return followFeignClient.isFollowed(followDTO);
    }

    @Operation(summary = "获取关注列表")
    @PostMapping("/getFollowList")
    Result<List<FollowVO>> getFollowList(@RequestBody PageDTO pageDTO, HttpServletRequest request) {
        if (pageDTO.getId() == 0) {
            pageDTO.setId(HttpUtils.getId(request));
        }
        return followFeignClient.getFollowList(pageDTO);
    }

    @Operation(summary = "获取粉丝列表")
    @PostMapping("/getFansList")
    Result<List<FollowVO>> getFansList(@RequestBody PageDTO pageDTO, HttpServletRequest request) {
        if (pageDTO.getId() == 0) {
            pageDTO.setId(HttpUtils.getId(request));
        }
        return followFeignClient.getFansList(pageDTO);
    }

}
